<?php // no direct access
defined('_JEXEC') or die('Restricted access');

jimport('mylibs.function');
jimport('mylibs.globalModel');

$cparams =& JComponentHelper::getParams('com_media');
$globalModel = new globalModel();
//$template_dir = $this->baseurl.'/templates/mwc_careitec/assets/';
$template_dir = '/templates/mwc_careitec/assets/';

if($_SERVER['HTTP_REFERER'] == '1'){
    $referer = $_SERVER['HTTP_REFERER'];    
}   
else{
    $referer = 'javascript:history.go(-1);';
}    

$menu_id    = JRequest::getVar('Itemid', 0, 'get');
$partner_id = JRequest::getVar('id', 0, 'get');
$cat_id     = JRequest::getVar('category_id', 0, 'get'); 
$current_id = JRequest::getVar('id', 0, 'get');  

$menus = &JSite::getMenu();                                             
$menu  = $menus->getActive();  
$ignore = $menu->query['id'];   

$title = $menu->name;
$doc =& JFactory::getDocument();
$doc->setTitle($title);   
?>  

<div id="main" class="p15t">
    <div class="w214 float_left"> 
        <!-- Menu -->
        <div class="w214 left_menu m10b"> 
            <div class="left_menu">
                <?php echo $globalModel->renderSubmenus($menu_id, $sec_id, $cat_id, $ignore); ?>
                
                <?php if(1==0){ ?>
                <ul class="parent_menu">    
                    <li class="curr_left_menu">
                        <a href="javascript:void(0);"><?php echo $menu->name; ?></a> 
                        <ul class="child_menu">                                
                            <?php 
                            $sub_menu = $globalModel->getContentByCategory($cat_id, $ignore);
                            foreach($sub_menu as $key => $value ){                                  
                                //$selected = $current_id == $value['id'] ? ' class="active"'   : '';                                
                                $current  = $current_id == $value['id'] ? ' class="curr_sub"' : '';
                                $link = 'index.php?option=com_content&view=article&id=' . $value['id'] . '&category_id=' . $cat_id . '&Itemid=' . $menu_id . '&emulate=1';
                                ?>    
                                <li<?php //echo $selected; ?>>
                                    <a <?php echo $current; ?> href="<?php echo $link; ?>" ><?php echo $value['title'];?></a>
                                </li>                  
                            <?php } ?> 
                        </ul>
                    </li> 
                </ul>
                <?php } ?>
            </div>
            <div class="left_menu_bot"></div>
        </div>
               
        <!-- Book -->
        <div class="w214 po m10b"> 
            <?php $link = $globalModel->getLeftColumnBookLink(); ?>             
            <a href="<?php echo $link; ?>"><img src="<?php echo $template_dir; ?>images/book_banner.png" alt="" /></a>                        
        </div>
        
        <!-- Article -->           
        <div class="w214">
            <div class="ads_sub_top"></div>
            <div class="ads_sub_mid">
                <div class="w186 mc p10t p10b">
                    <?php                    
                    $arr_data2 = $globalModel->getLeftColumnArticle();
                    foreach($arr_data2 as $key => $value){    
                        $text = strip_tags($value['introtext']);
                        $text = strlen($text) > 100 ? mb_substr($text, 0, 100, 'UTF-8') : $text;
                        $link = $globalModel->getLeftColumnArticleLink($value['id']);
                        ?> 
                        <?php if(1==0){ ?>
                        <a href="<?php echo $link; ?>"><img src="<?php echo $template_dir; ?>images/banner_ads_sub.jpg" alt="<?php echo $value['title'];?>" /></a>
                        <?php } ?>
                        <a href="<?php echo $link; ?>"><img src="<?php echo $value['article_image']; ?>" alt="<?php echo $value['title'];?>" /></a>                        
                        <p class="p5t"><?php echo $text; ?>...<a href="<?php echo $link; ?>"><?php echo JText::_('READ_MORE'); ?></a></p>                            
                    <?php } ?>                    
                </div>
            </div>
            <div class="ads_sub_bot"></div>
        </div>    
    </div>
    
    <div class="w708 bg_left_col2 float_right p22l">
        <div class="w708 bg_tt_sub1">
            <h2 class="p5t float_left"><?php echo $menu->name; ?></h2>
            <p class="float_right p5t" style="display:none"><a href="#"><img src="<?php echo $template_dir; ?>images/tilbage_icon.png" alt="" /> Tilbage</a></p>
            <br style="clear:both" />
        </div>
         
        <div class="w708">
            <?php
            /*
            $num_cols = $this->params->def('num_columns', 2);
            $num_intro = $this->params->get('num_intro_articles', 8);
            $i = $this->pagination->limitstart;
            $numIntroArticles = $i + $num_intro;
            
            for ($z = 0; $z < $num_cols; $z ++){              
                echo '<div class="w708 m15b">';
                              
                $rows = (int) ($num_intro / $num_cols);
                $cols = ($num_intro % $num_cols);
                $loop = (($z < $cols)? 1 : 0) + $rows; 
                for($y = 0; $y < $loop; $y ++){
                    $class = $y % 2 == 0 ? 'float_left' : 'float_right';
                    echo '<div class="bg_pro w347 ' . $class . '">';
                    
                    $target = $i + ($y * $num_cols) + $z;
                    if ($target < $this->total && $target < $numIntroArticles){
                        $this->item =& $this->getItem($target, $this->params);
                        echo $this->loadTemplate('item');
                    }
                    
                    echo '</div>'; 
                }               
                
                echo '<div class="cb"></div>';
                echo '</div>';   
            } 
            */
            
            $num_cols = $this->params->def('num_columns', 2);
            $num_intro = $this->params->get('num_intro_articles', 8);
            $start = $this->pagination->limitstart;             
            
            for ($i = $start; $i < $num_intro; $i ++){
                if($i % 2 == 0){              
                    echo '<div class="w708 m15b">';
                }
                  
                if($i < $this->total){                        
                    $class = $i % 2 == 0 ? 'float_left' : 'float_right';
                    echo '<div class="bg_pro w347 ' . $class . '">'; 
                     
                    $this->item =& $this->getItem($i, $this->params);
                    echo $this->loadTemplate('item'); 
                    
                    echo '</div>';
                }
                                      
                if($i % 2 != 0){
                    echo '<div class="cb"></div>';
                    echo '</div>';   
                }
            } 
            ?>  
            
            <div class="pt w708">
                <ul>                       
                    <?php if ($this->params->get('show_pagination') >= 2 && $this->pagination->get('pages.total') > 1) : ?>        
                        <?php if ($this->params->def('show_pagination_results', 1)) : ?>
                            <?php echo $this->pagination->getPagesLinks(); ?>
                        <?php endif; ?>
                    <?php endif; ?>               
                </ul>
                <br class="cb" />
            </div> 
        </div>
        
    </div>
    <div class="cb"></div>
</div>

<div id="footer" class="bg_foot_sub">
    <div class="w950 mc p15b">
        <p class="float_left">Copyright © <?php echo date('Y'); ?> <a href="index.html">CAREITEC.DK</a>. All rights reserved.</p>
        <p class="float_right">Design by <a href="mywebcreations.dk" target="_blank">My Web Creations</a></p>
        <br style="clear:both" />
    </div>
</div>
